<template>
  <a-card>
    <div style="margin-top: 10px" :bordered="false">
      <a-tabs default-active-key="1" @change="callback" class="nav_active">
        <!-- 加载的组件  -->
        <!-- 待办任务 tab -->
        <a-tab-pane key="1" tab="待办任务">
          <waitTask
            :FlowName="FlowName"
            ref="waitingTask"
            @send-record="checkHandle"
          ></waitTask>
        </a-tab-pane>

        <!-- 已办任务 tab -->
        <a-tab-pane key="2" tab="已办任务" force-render>
          <!-- 已办任务 组件 -->
          <finishTask
            :FlowName="FlowName"
            ref="finishingTask"
            @send-record="finishCheck"
          ></finishTask>
        </a-tab-pane>
      </a-tabs>

      <a-modal v-model="dialogVisible" width="60%">
        <!-- Modal 页脚按钮 -->
        <template slot="footer">
          <!-- 所有的按钮 -->
          <modalBar
            :duty_name="duty_name"
            :tabKey="tabKey"
            :nextTaskarray="nextTaskarray"
            :assigneeArray="ASSIGNEE_array"
            :nextStepType="next_step_type"
            @send-task="sendTask"
            @close-modal="closeModal"
            @end-task="endTask"
          ></modalBar>
        </template>

        <!-- Modal 对话框内容 -->
        <div id="printTest">
          <a-divider>生产领料申请</a-divider>

          <a-descriptions
            title
            bordered
            :column="{ xxl: 3, xl: 3, lg: 3, md: 3, sm: 1, xs: 1 }"
            style="text-align: right"
          >
            <a-descriptions-item label="申请单号">
              <div style="text-align: left">
                <span style="border: 0">{{ form.applyNumber }}</span>
              </div>
            </a-descriptions-item>
            <a-descriptions-item label="申请日期">
              <div style="text-align: left">
                <span style="border: 0">{{ form.applyDate }}</span>
              </div>
            </a-descriptions-item>
            <!-- <a-descriptions-item label="所属单位">
              <div style="text-align: left">
                <span style="border: 0">{{ form.affiliation }}</span>
              </div>
            </a-descriptions-item> -->
            <a-descriptions-item label="申请仓库">
              <div style="text-align: left">
                <span style="border: 0">{{ form.applyWarehouse }}</span>
              </div>
            </a-descriptions-item>
            <a-descriptions-item label="申请部门">
              <div style="text-align: left">
                <span style="border: 0">{{ form.applyDepartment }}</span>
              </div>
            </a-descriptions-item>
            <a-descriptions-item label="申请人">
              <div style="text-align: left">
                <span style="border: 0">{{ form.applier }}</span>
              </div>
            </a-descriptions-item>
            <a-descriptions-item label="产成品仓库">
              <div style="text-align: left">
                <span style="border: 0">{{ form.finishGoodsWarehouse }}</span>
              </div>
            </a-descriptions-item>
            <a-descriptions-item label="所属分厂">
              <div style="text-align: left">
                <span style="border: 0">{{ form.ownedBranch }}</span>
              </div>
            </a-descriptions-item>
            <a-descriptions-item label="产成品分类">
              <div style="text-align: left">
                <span style="border: 0">{{ form.finishedProductType }}</span>
              </div>
            </a-descriptions-item>
            <!-- <a-descriptions-item label="供应商">
              <div style="text-align: left">
                <span style="border: 0">{{ form.supplier }}</span>
              </div>
            </a-descriptions-item> -->
            <a-descriptions-item label="备注">
              <div style="text-align: left">
                <span style="border: 0">{{ form.remarks }}</span>
              </div>
            </a-descriptions-item>
          </a-descriptions>
          <a-divider>物品信息</a-divider>
          <a-table
            :columns="columns"
            :data-source="dataSource"
            :scroll="{ x: 2000 }"
          >
            <template slot="reallyCount" slot-scope="text, record">
              <a-input-number
                :disabled="
                  duty_name == workflow_Array[1] && tabKey == 1 ? false : true
                "
                v-model="record.reallyCount"
                :precision="precision"
              ></a-input-number>
            </template>
            <template slot="transferPurchaseOrderNum" slot-scope="text, record">
              <a-input-number
                :disabled="
                  duty_name == workflow_Array[1] && tabKey == 1 ? false : true
                "
                v-model="record.transferPurchaseOrderNum"
                :precision="precision"
              ></a-input-number>
            </template>
            <template slot="isTransfer" slot-scope="text, record">
              <a-select
                :disabled="
                  duty_name == workflow_Array[1] && tabKey == 1 ? false : true
                "
                default-value=""
                v-model="record.isTransfer"
                style="width: 50%"
              >
                <a-select-option
                  v-for="item in isTransferyList"
                  :key="item.title"
                  :value="item.id"
                >
                  {{ item.name }}
                </a-select-option>
              </a-select>
            </template>
          </a-table>
          <a-descriptions
            title
            bordered
            :column="{ xxl: 3, xl: 3, lg: 3, md: 3, sm: 1, xs: 1 }"
            style="text-align: right"
          >
          </a-descriptions>

          <a-divider>流程审批意见</a-divider>

          <!--  动态生成工作流填入意见  -->
          <a-descriptions
            title
            bordered
            :column="{ xxl: 3, xl: 3, lg: 3, md: 3, sm: 1, xs: 1 }"
            style="text-align: right"
            size="small"
          >
            <a-descriptions-item
              v-for="(item, index) in workForm"
              :key="index"
              :label="item.label"
              :span="3"
              style="width: 200px"
            >
              <div>
                <a-textarea
                  v-model="item.desc"
                  :disabled="
                    duty_name == workflow_Array[index] && tabKey == 1
                      ? false
                      : true
                  "
                  style="background-color: white; color: black; width: 100%"
                  :auto-size="{ minRows: 2 }"
                />
              </div>
              <div style="margin-top: 10px; text-align: left">
                <a-row>
                  <a-col :span="9">
                    <a-radio-group
                      v-model="item.radio_value"
                      @change="radio_Change(index)"
                    >
                      <a-radio
                        style="margin-left: 5px"
                        :value="1"
                        :disabled="
                          duty_name == workflow_Array[index] && tabKey == 1
                            ? false
                            : true
                        "
                      >
                        同意
                      </a-radio>
                      <a-radio
                        :value="2"
                        :disabled="
                          duty_name == workflow_Array[index] && tabKey == 1
                            ? false
                            : true
                        "
                      >
                        不同意
                      </a-radio>
                    </a-radio-group>
                  </a-col>
                  <a-col :span="9">
                    签名：
                    <img
                      v-if="!item.signImg"
                      :src="item.sign"
                      style="width: 100px; height: 30px"
                    />
                    <span v-if="item.signImg">{{ item.sign }}</span>
                  </a-col>
                  <a-col :span="6">日期：{{ item.date }}</a-col>
                </a-row>
              </div>
            </a-descriptions-item>
          </a-descriptions>
        </div>
      </a-modal>
    </div>
  </a-card>
</template>

<script>
// 加载 工作流变动接口
import { workflowHttp } from "../../services/modules/workFlow";
const wfHttp = new workflowHttp();

// 已办任务组件
import waitTask from "../../components/common/waitTask";

// 已办任务组件
import finishTask from "../../components/common/finishTask";

// 按钮组件
import modalBar from "../../components/common/modalBar";

// 物品信息表格
const columns = [
  {
    title: "序号",
    dataIndex: "key",
    key: "key",
    align: "center",
  },
  // {
  //   title: "所属单位",
  //   dataIndex: "affiliation",
  //   key: "affiliation",
  //   align: "center",
  //   scopedSlots: { customRender: "affiliation" },
  // },
  {
    title: "仓库名称",
    dataIndex: "warehouse",
    key: "warehouse",
    align: "center",
    scopedSlots: { customRender: "warehouse" },
  },

  {
    title: "存货编码",
    dataIndex: "inventoryNo",
    key: "inventoryNo",
    align: "center",
    scopedSlots: { customRender: "inventoryNo" },
  },
  {
    title: "存货名称",
    dataIndex: "inventoryName",
    key: "inventoryName",
    align: "center",
    scopedSlots: { customRender: "inventoryName" },
  },
  {
    title: "规格型号",
    dataIndex: "specificationsModel",
    key: "specificationsModel",
    align: "center",
    scopedSlots: { customRender: "specificationsModel" },
  },

  {
    title: "单位",
    key: "unit",
    dataIndex: "unit",
    align: "center",
    scopedSlots: { customRender: "unit" },
  },
  {
    title: "申请数量",
    dataIndex: "applyCount",
    key: "applyCount",
    align: "center",
    scopedSlots: { customRender: "applyCount" },
  },
  {
    title: "实发数量",
    dataIndex: "reallyCount",
    key: "reallyCount",
    align: "center",
    scopedSlots: { customRender: "reallyCount" },
  },
  {
    title: "转采购数量",
    dataIndex: "transferPurchaseOrderNum",
    key: "transferPurchaseOrderNum",
    align: "center",
    scopedSlots: { customRender: "transferPurchaseOrderNum" },
  },
  {
    title: "是否转采购",
    dataIndex: "isTransfer",
    key: "isTransfer",
    align: "center",
    scopedSlots: { customRender: "isTransfer" },
  },
  // {
  //   title: "产成品分类",
  //   key: "finishGoodsType",
  //   dataIndex: "finishGoodsType",
  //   align: "center",
  //   scopedSlots: { customRender: "finishGoodsType" },
  // },
  {
    title: "备注",
    key: "remark",
    dataIndex: "remark",
    align: "center",
    scopedSlots: { customRender: "remark" },
  },
];
const dataSource = [];
export default {
  components: {
    waitTask,
    finishTask,
    modalBar,
  },
  data() {
    return {
      isTransferyList: [
        {
          name: "是",
          id: 1,
        },
        {
          name: "否",
          id: 2,
        },
      ],
      flag: true,
      precision: 3, //保留3位小数
      columns,
      dataSource,
      // ------------ 工作流传递参数 ----------------

      // 申请人数据
      form: {},

      applicantName: "", // 申请人姓名
      applicantDate: "", //  申请人日期

      workForm: [], // 工作流数据

      Label: ["分厂厂长意见", "仓库管理员意见"],

      ASSIGNEE_: "", // 要提交的办理人
      tabKey: 1, // 全局 tab Key
      dialogVisible: false, // 办理 modal 显示
      // ------ 工作流产生数据 ------------

      // ------ 工作流通用数据
      FlowName: "生产领料", // 流程名称
      checkFlowName: "生产领料流程", //流程名称
      duty_name: "", // 当前任务进程名称
      workflow_Array: [], // 工作流数组，记录了当前工作流的所有流程步骤
      storeId: "", // 存储 任务ID ，待办任务中，提交按钮 需要提交任务ID

      ACT_ID: "", //审批的流程ID

      updateArr: [], //!修改数据的数组
      // ------ 传递到 modalBar 组件的数据
      nextTaskarray: [], // 下一级任务节点数组
      ASSIGNEE_array: [], // 办理人数组
      next_step_type: "", // 用来控制下一步任务是单选还是多选,下一步任务办理人是单选还是多选
    };
  },
  computed: {},
  mounted() {
    this.getDutyInfo();
  },
  methods: {
    // ---------- 工作流方法 ----------

    // tab 标签页 的回调函数
    callback(key) {
      if (key === "1") {
        // 待办任务列表
        this.tabKey = 1;
        // 刷新代办任务列表
        this.checkData = [];
        this.refreshCheckTask();
      } else if (key === "2") {
        // 已办任务列表
        this.tabKey = 2;
        this.finishData = [];
        // this.refreshFinishTask();
        // 刷新已办任务列表
      }
    },

    // 根据当前流程渲染表单,用来控制工作流程中哪一部分可以填写
    getDutyInfo() {
      let query_name = "?name=" + this.FlowName;
      let queryPath = "?name=" + this.checkFlowName;
      console.log("查询路径", query_name);
      console.log("查询路径2", queryPath);
      wfHttp.getProcessstepByFlowName(queryPath).then((res) => {
        console.log("工作流程步骤信息:::", res);
        this.workflow_Array = [];
        this.workflow_Array.push(res.result.firstTask);
        let array = res.result.processStep.split(",");
        for (let i = 0; i < array.length; i++) {
          this.workflow_Array.push(array[i]);
        }
        console.log("this.workflow_Array=====>", this.workflow_Array);
        this.workForm = [];
        for (let i = 0; i < this.workflow_Array.length; i++) {
          let data = {
            desc: "", // 描述框
            signImg: "true",
            sign: "",
            date: "",
            label: this.Label[i], // 标签
            radio_value: "",
          };
          this.workForm.push(data);
        }
        console.log("工作流程步骤信息:::", this.workForm);
      });
    },

    //------------- 电子签名处理函数 -------------------

    getSignImg(data) {
      let signImg = "";
      if (data == null || data == "") {
        signImg = true;
      } else {
        signImg = false;
      }
      return signImg;
    },

    // 根据 电子签名显示标识 来控制如何显示,sign 是渲染的签名，
    // signImg 签名如何显示控制器，sign_name 申请人姓名，sign_Img申请人电子签名
    showSignImg(signImg, sign_name, sign_Img) {
      var sign = "";
      if (signImg == true) {
        sign = sign_name;
      } else {
        sign = sign_Img;
      }
      return sign;
    },
    // 单选按钮触发事件
    radio_Change(index) {
      console.log(this.workForm[index]);
      if (this.workForm[index].radio_value == 1) {
        this.workForm[index].desc = "同意";
      } else {
        this.workForm[index].desc = "不同意";
      }
    },
    // -------------- tab 1 待办任务 ----------------------
    // 重新刷新待办任务列表
    refreshCheckTask() {
      this.$refs.waitingTask.postTasksList();
    },

    // 待办任务组件触发函数, 点击办理按钮触发
    checkHandle(record) {
      console.log("待办任务record==========》", record);
      this.id = parseInt(record.id);
      console.log("this.id=======>", this.id);
      this.getDutyInfo();
      this.ASSIGNEE_Key = [];
      // 工作流表单清空,重新构造
      let PROC_INST_ID_ = record.PROC_INST_ID_; // 实例流程ID
      this.storeId = record.ID_;
      let FILENAME = record.DGRM_RESOURCE_NAME_;
      // console.log("文件名称:::::", FILENAME);
      let singleFormData = new FormData();

      singleFormData.append("PROC_INST_ID_", PROC_INST_ID_);
      singleFormData.append("ID_", this.storeId);
      singleFormData.append("FILENAME", FILENAME);
      wfHttp.postProcessInformation(singleFormData).then((res) => {
        console.log("返回的总体工作流数据+++++++++++", res);

        this.duty_name = res.result.currentTask; // 获取当前的任务
        console.log("当前任务名称:::", this.duty_name);

        this.nextTaskarray = []; // 重置下一步任务列表
        this.ASSIGNEE_array = []; // 重置下一步办理人列表

        // 解析下一步任务数组、解析下一步人员数组
        for (let i = 0; i < res.result.nextUserNameList.length; i++) {
          this.nextTaskarray.push(res.result.nextUserNameList[i].taskName); // 下一步任务数组

          // 下一步人员信息
          let keysArray = Object.keys(
            res.result.nextUserNameList[i].userNameAndId
          );
          // console.log("获取所有用户id:::::", keysArray);

          for (let j = 0; j < keysArray.length; j++) {
            // 包含 key 值
            // console.log(keysArray[j]);
            // console.log(this.ASSIGNEE_Key.indexOf(keysArray[j]) == -1);

            if (this.ASSIGNEE_Key.indexOf(keysArray[j]) == -1) {
              let data = {
                userId: keysArray[j],
                userName:
                  res.result.nextUserNameList[i].userNameAndId[keysArray[j]],
              };
              // console.log("用户数据::::", data);
              this.ASSIGNEE_array.push(data);
              this.ASSIGNEE_Key.push(keysArray[j]);
            }
          }
        }
        // console.log("下一步任务数组:::", this.nextTaskarray);
        console.log("下一步人员信息:::", this.ASSIGNEE_array);
        console.log("下一步办理人ASSIGNEE_Key:::", this.ASSIGNEE_Key);

        let varList = res.result.varList; // 申请人提交的数据
        let hitaskList = res.result.hitaskList; // 工作流产生数据
        console.log("申请人提交数据:::", varList);
        console.log("hitaskList工作流产生数据:::", hitaskList);

        // --------- 申请人数据 ---------------
        this.form = {
          applyNumber: varList[0].TEXT_, //生产领料申请单号
          applyDate: varList[10].TEXT_, //申请日期
          affiliation: varList[5].TEXT_, //所属单位
          applyWarehouse: varList[1].TEXT_, //申请仓库
          applyDepartment: varList[2].TEXT_, //申请部门
          applier: varList[3].TEXT_, //申请人
          finishGoodsWarehouse: varList[6].TEXT_, //产成品仓库
          ownedBranch: varList[8].TEXT_, //所属分厂
          finishedProductType: varList[9].TEXT_, //产成品分类

          remarks: varList[4].TEXT_, //备注
        };
        if (this.form.remarks == "null") {
          this.form.remarks = "";
        }
        this.ACT_ID = hitaskList[hitaskList.length - 1].ACT_ID_;
        this.applicantName = hitaskList[1].ASSIGNEE_;
        this.applicantDate = hitaskList[1].START_TIME_;
        console.log("ACT_ID============", this.ACT_ID);

        // =============生产领料单物品列表================
        this.dataSource = [];
        for (let m = 13, n = 1; m < varList.length; m++, n++) {
          let array = [];
          array = varList[m].TEXT_.split(";"); //生产领料单的内容
          console.log("array=====================>", array);
          if (array[8] == "null") {
            array[8] = "";
          }
          let dataSource1 = {
            key: n,
            id: array[0], //生产领料主键id
            affiliation: array[1], //所属单位
            warehouse: array[2], //仓库名称
            inventoryNo: array[3], //存货编码
            inventoryName: array[4], //存货名称
            specificationsModel: array[5], //规格型号
            unit: array[6], //单位
            applyCount: array[7], //申请数量
            reallyCount: array[8], //实发数量
            finishGoodsType: array[11], //产成品分类
            remark: array[14], //备注
            transferPurchaseOrderNum: array[15], //转采购数量
            isTransfer: 2, //是否转采购
          };
          this.dataSource.push(dataSource1);
        }

        // ===========更新数组开始==============
        // 更新数组
        this.updateArr = [];
        for (let i = 13, k = 0; i < varList.length; i++, k++) {
          let data2 = {
            id_: varList[i].ID_, //更新记录ID
            warehouseProducePickingContentEntity: {}, //生产领料单修改对象
            text_: varList[i].TEXT_, //更新记录内容
          };
          console.log("data2！！！！！！！！！！！！", data2);
          data2.warehouseProducePickingContentEntity = {
            actualQuantity: this.dataSource[k].reallyCount,
            id: parseInt(this.dataSource[k].id),
            transferPurchaseOrderNum:
              this.dataSource[k].transferPurchaseOrderNum,
            isTransfer: this.dataSource[k].isTransfer,
          };
          console.log("data2data==========>", data2);
          this.updateArr.push(data2);
        }
        console.log("需要更新的数据==============》", this.updateArr);
        console.log("this.dataSource", this.dataSource);
        console.log("hitaskList=========>", hitaskList);
        console.log("hitaskList.length=========>", hitaskList.length);
        console.log("this.workflow_Array======>", this.workflow_Array);
        // --------- 工作流数据 ---------------
        // 利用for 循环来渲染数据,渲染的数据是目前已经完成的任务

        for (let j = 0; j < hitaskList.length; j++) {
          for (let i = 0; i < this.workflow_Array.length; i++) {
            if (hitaskList[j].ACT_NAME_ == this.workflow_Array[i]) {
              console.log(j, "----j----", hitaskList[j].ACT_NAME_);
              // console.log(i, "----i----", hitaskList[j].ACT_NAME_);
              if (hitaskList[j].END_TIME_ != null) {
                this.workForm[i].desc = hitaskList[j].TEXT_; // 下一个描述
                this.workForm[i].date = hitaskList[j].END_TIME_.substring(
                  0,
                  10
                );
                this.workForm[i].signImg = this.getSignImg(hitaskList[j].eUrl);
                this.workForm[i].sign = this.showSignImg(
                  this.workForm[i].signImg,
                  hitaskList[j].ASSIGNEE_,
                  hitaskList[j].eUrl
                );
              }
            }
          }
        }

        this.dialogVisible = true;
      });
    },

    // 给办理提交函数提供接口，并返回信息
    do_submit(data) {
      this.workflow_Array.forEach((item, index) => {
        if (this.duty_name == item && this.workForm[index].desc !== "") {
          wfHttp.postHandleTasks(data).then((res) => {
            if (res && res.code === 200) {
              this.$message.success("发送成功");
              // 刷新待办任务列表
              this.checkData = [];
              this.dialogVisible = false;
              this.refreshCheckTask();
            } else {
              this.$message.error("发送失败");
            }
          });
        }
        if (this.duty_name == item && this.workForm[index].desc == "") {
          this.$message.error("请选择意见");
        }
      });
    },
    // 办理结束
    do_end(data) {
      wfHttp.postHandleTasks(data).then((res) => {
        if (res && res.code === 200) {
          this.$message.success("结束成功");
          this.closeModal(); // 结束父组件对话框
          this.refreshCheckTask(); // 待办列表刷新
          // 刷新待办任务列表
        } else {
          this.$message.error("结束失败");
        }
      });
    },

    //  发送按钮触发函数
    sendTask(data) {
      console.log("选择好的下一步办理人数据::::", data);
      let singleFormData = new FormData();
      singleFormData = data;
      singleFormData.append("ID_", this.storeId);
      singleFormData.append("msg", "yes");

      if (this.ACT_ID == "PickingUT3") {
        console.log("hhhhhhhh");
        this.updateSendTask(singleFormData);
      } else {
        // 一次提交一条记录
        for (let i = 0; i < this.workflow_Array.length; i++) {
          if (this.duty_name == this.workflow_Array[i]) {
            // console.log("当前工作流的申请意见", this.workForm[i].desc);
            singleFormData.append("OPINION", this.workForm[i].desc);
            break;
          }
        }
        console.log("要提交的数据:::::", singleFormData);
        this.do_submit(singleFormData); // 提交
      }
    },

    //! 更新接口
    updateSendTask(data) {
      console.log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!::::", this.dataSource);

      let flag = 0;
      this.dataSource.forEach((element) => {
        element.reallyCount = String(element.reallyCount);
        if (element.reallyCount == "") {
          flag = 1;
          console.log("flag1", flag);
        }
        element.isTransfer = String(element.isTransfer);
        if (element.isTransfer == "") {
          flag = 1;
          console.log("flag1", flag);
        }
      });
      console.log("flag2", flag);

      console.log("选择好的下一步办理人数据::::", data);
      let singleFormData = data;
      singleFormData.append("ID_", this.storeId);
      singleFormData.append("msg", "yes");
      console.log("this.storeId", this.storeId);
      let queryPath = "?processName=" + "生产领料流程";
      console.log("queryPath工作流修改接口", queryPath);
      let array = [];
      console.log("this.dataSource-------->", this.dataSource);
      for (let i = 0; i < this.dataSource.length; i++) {
        if (this.dataSource[i].reallyCount == "" || null) {
          this.$message.error("填写实发数量");
          return;
        }
        if (this.dataSource[i].isTransfer == "" || null) {
          this.$message.error("填选择是否转采购");
          return;
        }
        this.updateArr[i].text_ =
          this.dataSource[i].id +
          ";" +
          this.dataSource[i].affiliation +
          ";" +
          this.dataSource[i].warehouse +
          ";" +
          this.dataSource[i].inventoryNo +
          ";" +
          this.dataSource[i].inventoryName +
          ";" +
          this.dataSource[i].specificationsModel +
          ";" +
          this.dataSource[i].unit +
          ";" +
          this.dataSource[i].applyCount +
          ";" +
          this.dataSource[i].reallyCount +
          ";" +
          this.dataSource[i].transferPurchaseOrderNum +
          ";" +
          this.dataSource[i].isTransfer +
          ";";

        null +
          ";" +
          null +
          ";" +
          this.dataSource[i].finishGoodsType +
          ";" +
          this.dataSource[i].remark;

        this.updateArr[i].warehouseProducePickingContentEntity = {
          actualQuantity: Number(this.dataSource[i].reallyCount),
          transferPurchaseOrderNum: Number(
            this.dataSource[i].transferPurchaseOrderNum
          ),
          isTransfer: this.dataSource[i].isTransfer,
          id: parseInt(this.dataSource[i].id),
        };
        console.log(this.updateArr, "======================");
      }
      console.log("this.updateArr", this.updateArr);
      array = this.updateArr;
      console.log("array++++++++", array);

      wfHttp.updatechangeForm(queryPath, array).then((res) => {
        console.log("更新工作流打印res===========", res);
        if (res && res.code === 200) {
          for (let i = 0; i < this.workflow_Array.length; i++) {
            if (this.duty_name == this.workflow_Array[i]) {
              console.log("当前工作流的申请意见", this.workForm[i].desc);
              singleFormData.append("OPINION", this.workForm[i].desc);
              break;
            }
          }
          console.log("要提交的数据:::::", singleFormData);
          this.do_submit(singleFormData); // 提交
          this.flag = true;
        } else {
          this.$message.error("操作失败");
        }
      });
    },
    // 结束按钮
    endTask() {
      let singleFormData = new FormData();
      singleFormData.append("ID_", this.storeId);
      singleFormData.append("msg", "no");
      // 一次提交一条记录
      for (let i = 0; i < this.workflow_Array.length; i++) {
        if (this.duty_name == this.workflow_Array[i]) {
          singleFormData.append("OPINION", this.workForm[i].desc);
          break;
        }
      }
      console.log("要提交的数据:::::", singleFormData);
      this.do_end(singleFormData);
    },

    // -------------- tab 2 已办任务 ----------------------
    // 重新刷新已办任务列表
    refreshFinishTask() {
      console.log("已办任务", this.$refs);
      this.$refs.finishingTask.finishTaskList();
    },

    // 已办任务组件触发函数，点击详情触发
    finishCheck(record) {
      let PROC_INST_ID_ = record.PROC_INST_ID_; // 实例流程ID
      let FILENAME = record.FILENAME;
      let singleFormData = new FormData();
      singleFormData.append("PROC_INST_ID_", PROC_INST_ID_);
      singleFormData.append("FILENAME", FILENAME);

      wfHttp.postQueryHisInfo(singleFormData).then((res) => {
        if (res && res.code === 200) {
          console.log("已办任务列表+++++++++++", res);

          let varList = res.result.varList; // 申请人提交的数据
          let hitaskList = res.result.hitaskList; // 工作流产生数据
          console.log("申请人提交数据:::", varList);
          console.log("工作流产生数据:::", hitaskList);

          // --------- 申请人数据 ---------------
          this.form = {
            applyNumber: varList[0].TEXT_, //生产领料申请单号
            applyDate: varList[10].TEXT_, //申请日期
            affiliation: varList[5].TEXT_, //所属单位
            applyWarehouse: varList[1].TEXT_, //申请仓库
            applyDepartment: varList[2].TEXT_, //申请部门
            applier: varList[3].TEXT_, //申请人
            finishGoodsWarehouse: varList[6].TEXT_, //产成品仓库
            // supplier: varList[7].TEXT_, //供应商
            ownedBranch: varList[8].TEXT_, //所属分厂
            finishedProductType: varList[9].TEXT_, //产成品分类

            remarks: varList[4].TEXT_, //备注
          };
          this.applicantName = hitaskList[1].ASSIGNEE_;
          this.applicantDate = hitaskList[1].START_TIME_;
          this.dataSource = [];
          for (let m = 13, n = 1; m < varList.length; m++, n++) {
            let array = [];
            array = varList[m].TEXT_.split(";"); //生产领料单的内容
            console.log("array==============================>", array);
            if (array[9] == "undefined" || array[9] == "null") {
              array[9] = "";
            }
            if (array[8] == "undefined" || array[8] == "null") {
              array[8] = "";
            }
            let dataSource2 = {
              key: n,
              id: array[0], //生产领料主键id
              affiliation: array[1], //所属单位
              warehouse: array[2], //仓库名称
              inventoryNo: array[3], //存货编码
              inventoryName: array[4], //存货名称
              specificationsModel: array[5], //规格型号
              unit: array[6], //单位
              applyCount: array[7], //申请数量
              reallyCount: array[8], //实发数量
              finishGoodsType: array[11], //产成品分类
              remark: array[11], //备注
              transferPurchaseOrderNum: array[9], //转采购数量
              isTransfer: array[10] == 2 ? "否" : "是", //是否转采购
            };
            this.dataSource.push(dataSource2);
          }
          console.log("this.dataSource======>", this.dataSource);
          // --------- 工作流数据 ---------------
          // 利用for 循环来渲染数据,渲染的数据是目前已经完成的任务

          for (let j = 0; j < hitaskList.length; j++) {
            for (let i = 0; i < this.workflow_Array.length; i++) {
              if (hitaskList[j].ACT_NAME_ == this.workflow_Array[i]) {
                console.log(hitaskList[j].ACT_NAME_);
                this.workForm[i].desc = hitaskList[j].TEXT_; // 下一个描述
                if (hitaskList[j].END_TIME_ != null) {
                  this.workForm[i].date = hitaskList[j].END_TIME_.substring(
                    0,
                    10
                  );
                }
                this.workForm[i].signImg = this.getSignImg(hitaskList[j].eUrl);
                this.workForm[i].sign = this.showSignImg(
                  this.workForm[i].signImg,
                  hitaskList[j].ASSIGNEE_,
                  hitaskList[j].eUrl
                );
              }
            }
          }

          this.dialogVisible = true;
        } else {
          this.$message.error("服务器异常");
        }
      });
    },

    //  父组件对话框结束
    closeModal() {
      this.dialogVisible = false;
    },
  },
};
</script>

<style lang="less" scoped>
.list-content-item {
  color: rgba(0, 0, 0, 0.45);
  display: inline-block;
  vertical-align: middle;
  font-size: 14px;
  margin-left: 40px;
  span {
    line-height: 20px;
  }
  p {
    margin: 4px 0 0;
    line-height: 22px;
  }
}
textarea {
  border: 0;
  border-radius: 5px;
  background-color: rgba(241, 241, 241, 0.98);
  width: 100%;
  height: 100px;
  padding: 10px;
  resize: none;
}
.tablehah {
  margin-top: 15px;
}
</style>
